<?php

namespace app\configure\controller;

use app\configure\model\ConfigRepairItemModel;
use app\configure\model\ConfigRepairModel;
use think\admin\Controller;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class Repair extends Controller
{
    /**
     * 当前操作数据库
     * @var string
     */
    private string $table = 'ConfigRepair';

    /**
     * 报事报修管理
     * @auth true
     * @menu true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function index()
    {
        $this->title = '报事报修管理';
//        $this->type =$this->request->param('type', 'index');
        $this->_query(ConfigRepairModel::class)->like('name')->order('id desc')->page(true, true);
    }

    /**
     * 添加服务
     * @auth true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function add()
    {
        $this->_form(ConfigRepairModel::class, 'form');
    }

    /**
     * 修改
     * @auth true
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     * @throws DbException
     */
    public function edit()
    {
        $this->_applyFormToken();
        $this->_form(ConfigRepairModel::class, 'form');
    }

    public function _form_filter()
    {

    }


    public function del()
    {
    }

    /**
     * 删除
     * @auth true
     * @throws DbException
     */
    public function remove()
    {
        $this->_delete(ConfigRepairModel::class);
    }

    /**
     * 查看详情
     * @auth true
     * @return void
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function detail()
    {
        $this->title = '报事报修项目管理';
        $id = $this->request->get('id');
        $model = new ConfigRepairItemModel();
        $list = $model->where(['nid' => $id])->select();
        $list = $list->toArray();
        $this->fetch('item', ['list' => $list, 'nid' => $id]);
    }

    /**
     * 添加服务
     * @auth true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function addItem()
    {
        $id = $this->request->get('nid');
        $this->assign('nid', $id);
        $this->_form(ConfigRepairItemModel::class, 'form_item');
    }

    /**
     * 修改
     * @auth true
     * @throws ModelNotFoundException
     * @throws DataNotFoundException
     * @throws DbException
     */
    public function editItem()
    {
        $id = $this->request->get('nid');
        $this->assign('nid', $id);
        $this->_applyFormToken();
        $this->_form(ConfigRepairItemModel::class, 'form_item');
    }


    public function delItem()
    {
    }

    /**
     * 删除
     * @auth true
     * @throws DbException
     */
    public function removeItem()
    {
        $this->_delete(ConfigRepairItemModel::class);
    }
}